package com.ajr.core.visma;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import org.apache.log4j.Logger;

import se.codevision.jinterlink.JInterLink;
import se.codevision.jinterlink.registers.Customer;
import se.codevision.jinterlink.registers.JInterLinkRegisterFactory;

import com.ajr.core.CountryCodes;
import com.ajr.core.CustomerObject;
import com.ajr.core.Orders;
import com.ajr.core.Settings;
import com.ajr.core.oscommerce.OSCommerceAction;
import com.ajr.util.MessageBundle;
import com.jnr.servlets.SubmitOrder;
import com.mysql.jdbc.ResultSetMetaData;

public class CustomersAction {
	Logger logger = Logger.getLogger(CustomersAction.class);


	public ExportResult inserCustomer(CustomerObject customerObject,boolean updateCustomer) {
		logger.info("inserting customer "
				+ customerObject.getCustomerName());
		String s1;
		String s2;
		boolean flag;
		Customer customer;
		customer = null;
		ExportResult exportResult = new ExportResult();

		boolean companyCustomer = false;
		if (customerObject.getCompayName() != null
				&& customerObject.getCompayName().length() > 0) {
			companyCustomer = true;
		}

		try {
			customer = JInterLinkRegisterFactory.createCustomer();
			boolean flag1 = false;
			/*
			 * if(s == null) { flag1 = true;
			 * if(!b.isLetSpcsChooseCustomerNumber()) {
			 * customer.setNumber(m.A()); boolean flag2 = customer.find();
			 * if(flag2 && customer.getNumber().equals(m.A())) { flag1 = false;
			 * s = m.A(); flag = true; } } }
			 */
			// if(s1.equals("0"))
			flag1 = true;

			/*
			 * if(flag1) if(s1.equals("0")) customer.reset(); else
			 * if(b.isLetSpcsChooseCustomerNumber()) { customer.reset(); } else
			 * { String s3 = (new
			 * StringBuilder()).append(b.getCustomerNumberPrefix
			 * ()).append(s2).toString(); customer.setNumber(s3); }
			 */

//			boolean find = false;
			boolean insertCustomer = true;
			String numstr = String.valueOf(customerObject.getCustomerNumber());
			
			String prefix = Settings.getInstance().getSpcsCustomerNumberSeries();
			if(prefix.length() > 0) {
				//numstr = String.valueOf((Integer.parseInt(numstr) + Integer.parseInt(prefix)));
				numstr = prefix + numstr; 
			}
			
			if (!Settings.getInstance().isLetSpcsChooseCusomerNumber()) {
				customer.setNumber(numstr);
//				find = customer.find();
				if (customer.find() && customer.getNumber().equals(numstr)) {
					logger.info("Customer already exists");
					exportResult.setMessage(ExportResult.OSC_ORDER_EXPORT_SUCCESS_CODE,MessageBundle.getMessage("customer.exists")); //"Customer Already Exists"
//					find = true;
					insertCustomer = false;
				}
			}else {
				String spcsCustomerNumber = OSCommerceAction.getVismaCustomerNumber(String.valueOf(customerObject.getCustomerNumber()));
				customer.setNumber(spcsCustomerNumber);
//				find = customer.find();
				if (customer.find() && customer.getNumber().equals(spcsCustomerNumber)) {
					logger.info("Customer already exists");
					exportResult.setMessage(ExportResult.OSC_ORDER_EXPORT_SUCCESS_CODE,MessageBundle.getMessage("customer.exists")); //"Customer Already Exists"
//					find = true;
					insertCustomer = false;
				}
				logger.info("Custoemr not exists");
			}
			logger.info("number " + customer.getNumber());

			if (!insertCustomer) { // new customer
				customer.setNumber(numstr);
			} else {
				customer.reset();
				if(!Settings.getInstance().isLetSpcsChooseCusomerNumber()) {
					customer.setNumber(numstr);
				}
				//customer.setNumber(numstr);
			}
			// if(m.D() != null && m.D().length() > 0)
			if (companyCustomer) {
				customer.setName(customerObject.getCompayName());

			} else {
				customer.setName(customerObject.getCustomerName());

			}

			// else
			// customer.setName(m.L());
			customer.setMailingAddress(customerObject.getMailAdrress1());
			customer.setMailingAddress2(customerObject.getMailAddress2());
			customer.setZipcode(customerObject.getZipcode());
			customer.setCity(customerObject.getCity());
			customer.setCountry(customerObject.getCountry());
			
			String telephone = customerObject.getTelephone();
			if(telephone != null && telephone.length() > 0) {
				customer.setTelephone(telephone.split(",")[0]);
				
			}

			if (Settings.getInstance().isExportCustomerFaxAsTelphone2()) {
				customer.setTelephone2(customerObject.getCustomerFax());
				customer.setFax("");
			} else {
				customer.setTelephone2("");
				customer.setFax(customerObject.getCustomerFax());
			}

			if (Settings.getInstance().isIncludeCountryCode4Customers()) {
				customer.setCodeOfCountry(customerObject.getCountryCode());
			}

			if (companyCustomer) {
				customer.setDeliveryName(customerObject.getDeliveryCompany());

			} else {
				customer.setDeliveryName(customerObject.getDeliveryName());

			}
			customer.setDeliveryAddress(customerObject.getDeliveryAddress());
			customer.setDeliveryAddress2(customerObject.getDeliveryAddress2());
			customer.setDeliveryZipcode(customerObject.getDeliveryZipcode());
			customer.setDeliveryCity(customerObject.getDeliveryCity());
			customer.setDeliveryCountry(customerObject.getDeliveryCountry());
			customer.setDeliveryTelephone(customerObject.getDeliveryTelephone());
			// if(OSCommerce.getConfig().getApplication().getSpcs().isIncludeCustomerCountryCode())

			if (Settings.getInstance().isIncludeCountryCode4Customers()) {
				customer.setDeliveryCodeOfCountry(customerObject
						.getDeliveryCodeOfCountry());
			}
			
			logger.info("customerObject.getGroupId()  "+customerObject.getGroupId());

			if (Settings.getInstance().isUseCustomerGroup()) {
				customer.setCategory(String.valueOf(customerObject.getGroupId()));
//				customer.setCategory("0");
//				customer.setCategory("0");
			}else {
				if(Settings.getInstance().getSpcsCustomerGroup().length() > 0)
				customer.setCategory(Settings.getInstance().getSpcsCustomerGroup());
			}
			customer.setEmail(customerObject.getEmail());

			customer.setReference(customerObject.getReference());

			customerObject.print();

			// if(b.isUseCustomerGroup())
			// customer.setCategory(b.getCustomerGroup());

			// billing
			// customer.setc

			logger.info("Settings SPCS_CUSTOMER_SOCIAL_AND_TAX_ID_INCLUDE "+Settings.getInstance().isCustomerSocialAndTaxIDInclude());
			if (Settings.getInstance().isCustomerSocialAndTaxIDInclude()) {
				customer.setOrganisationNumber(customerObject
						.getOrganizationNumber());
			}
			// customer.setBool(arg0, arg1)

			String standardLanguageCode = Settings.getInstance()
					.getOSCommerceStandardLanguageID();
			

			if (standardLanguageCode != null
					&& standardLanguageCode.length() > 0) {
//				logger.info("language codes"+VismaEnvironment.getInstance().languageCodes);
				
				String code = OSCommerceAction.getLanguageCode(standardLanguageCode);
				customer.setCodeOfLanguage(code);
			}

			/*if (Settings.getInstance().isPlaceNewOrUpdatedCusomer4Group()) {

			}*/
			
			if(!Settings.getInstance().isExportJInterBrokerAddress() && companyCustomer) {
				// include less
				
				customer.setMailingAddress2(customerObject.getMailAdrress1());
				customer.setMailingAddress(customerObject.getCustomerName());
				
				customer.setDeliveryAddress(customerObject.getDeliveryName());
				customer.setDeliveryAddress2(customerObject.getDeliveryAddress());
			}else { // already set as default
//				customer.setDeliveryAddress2(customerObject.getDeliveryAddress2());
//				customer.setMailingAddress2(customerObject.getMailAddress2());
				
			}

			/* customer.updateRecord() */

			if (insertCustomer) {
				logger.info("Inserting new customer");
				JInterLink.getInstance().add(customer);
				exportResult.setMessage(ExportResult.OSC_CUSTOMER_EXPORT_SUCCESS_CODE,MessageBundle.getMessage("customer.inserted.success"));
			} else {
				if (updateCustomer) {
					logger.info("updating  customer");

					customer.updateRecord();
					exportResult.setMessage(ExportResult.OSC_CUSTOMER_UPDATE_SUCCESS_CODE,MessageBundle.getMessage("customer.update.success"));
				}else {
					logger.info("Doing nothing on customer record");
					exportResult.setMessage(ExportResult.OSC_CUSTOMER_UPDATE_SUCCESS_CODE,MessageBundle.getMessage("customer.not.updated"));
				}
			}

			logger.info((new StringBuilder()).append(
					"Created customer: ").append(customer.getNumber())
					.toString());
			exportResult.setCustomerNumber(customer.getNumber());
			exportResult.setStatus(true);
			if (Settings.getInstance().isExportSpcsJInterTables()) {
				OSCommerceAction.insertCustomerMapInsert(String
						.valueOf(customerObject.getCustomerNumber()), String
						.valueOf(customer.getNumber()));
			}
			
			
			
			return exportResult;
		} catch (Exception e) {
			exportResult.setStatus(false);
			exportResult.setMessage(ExportResult.OSC_CUSTOMER_EXPORT_FAILURE_CODE,e.getMessage());
			// exportResult.setStatus(false);
			logger.error("Error while exporting customer", e);
			
		} finally {
			if (customer != null)
				customer.release();
		}
		return exportResult;
	}

	// private String message = "";

	public ExportResult getCustomerId(int orderId,boolean updateCustomer) {
		boolean groupTableExists = OSCommerceAction.isTableExists("customers_groups");

		logger.info("inside getCustomerId");
		logger.info("Customer group existence "+groupTableExists);

		String sql = "select o.*,c.*,cu.*,a.*,cg.* from orders o,customers c,currencies cu,address_book a,customers_groups cg where "
				+ "c.customers_id=o.customers_id and "
				+ "c.customers_id=a.customers_id and "
				+ "c.customers_group_id=cg.customers_group_id and "
				+ "o.currency = cu.code and  " + "o.orders_id =" + orderId;
		
		if(!groupTableExists) {
			sql = "select o.*,c.*,cu.*,a.*,0 customers_group_id,'' customers_group_name,-1 customers_group_show_tax from orders o,customers c,currencies cu,address_book a where "
				+ "c.customers_id=o.customers_id and "
				+ "c.customers_id=a.customers_id and "
//				+ "c.customers_group_id=cg.customers_group_id and "
				+ "o.currency = cu.code and  " + "o.orders_id =" + orderId;
		}

		CustomerObject customerObject = new CustomerObject();

		ExportResult exportResult = new ExportResult();

		java.sql.Connection c = null;
		Statement stmt = null;
		ResultSet rs = null;

		try {
			String url = Settings.getInstance().getConnectionURL();
			String user = Settings.getInstance().getUserName();
			String password = Settings.getInstance().getPassword();
			String driver = Settings.getInstance().getDriverClassName();

			Class.forName(driver);
			// DriverManager.getConnection(url, user, password);
			// Session session = sessionFactory.openSession();
			// java.sql.Connection c =
			// sessionFactory.openSession().connection();
			c = DriverManager.getConnection(url, user, password);
			
			Statement stmt1 = c.createStatement();
			String sql1 = "select * from customers c,orders o " +
					"where orders_id= "+orderId+" and c.customers_id=o.customers_id";
			
			ResultSet rs1 = stmt1.executeQuery(sql1);
			if(!rs1.next()) {
				logger.info("Customer not exists for orderId "+orderId);
				exportResult.setCustomerExists(false);
				
				// new query
				sql = "select o.*,c.*,cu.*,cg.*,'' entry_company_tax_id,'' customers_personnummer from orders o,orders c,currencies cu,customers_groups cg where "
					+ "cg.customers_group_id=0 and "
					+ "o.orders_id=c.orders_id and "
//					+ "o.customers_id=a.customers_id and "
					+ "o.currency = cu.code and  " + "o.orders_id =" + orderId;
				
				if(!groupTableExists) {
					sql = "select o.*,c.*,cu.*,0 customers_group_id,'' customers_group_name,-1 customers_group_show_tax,'' entry_company_tax_id,'' customers_personnummer from orders o,orders c,currencies cu where "
//						+ "cg.customers_group_id=0 and "
						+ "o.orders_id=c.orders_id and "
//						+ "o.customers_id=a.customers_id and "
						+ "o.currency = cu.code and  " + "o.orders_id =" + orderId;
				}

//				logger.info("new query "+sql);
				rs1.close();
				stmt1.close();
			}else {
				rs1.close();
				stmt1.close();
				
			}

			stmt = c.createStatement();
			rs = stmt.executeQuery(sql);

			// logger.info(sql);

			if (rs.next()) {
				
				printValues(rs);

				int snumber = rs.getInt("c.customers_id");
				customerObject.setCompayName(rs
						.getString("o.billing_company"));
				customerObject.setCustomerName(rs.getString("o.billing_name"));
				customerObject.setCustomerNumber(snumber);
				// customerObject.setCustomerNumber(rs.getInt("customers_id"));
				customerObject.setMailAdrress1(rs
						.getString("o.billing_street_address"));
				customerObject
						.setMailAddress2(rs.getString("o.billing_suburb"));
				customerObject.setCity(rs.getString("o.billing_city"));
				String bcountry = rs.getString("o.billing_country");
				customerObject.setCountry(bcountry);
				customerObject.setTelephone(rs
						.getString("c.customers_telephone"));
//				customerObject.setTelephone2(rs
//						.getString("c.customers_telephone"));
				
				customerObject.setGroupName(rs.getString("customers_group_name"));
				customerObject.setGroupId(rs.getInt("customers_group_id"));
				
				try {
					customerObject.setCustomerFax(rs.getString("c.customers_fax"));
				} catch (Exception e) {
					// TODO: handle exception
				}

				customerObject.setZipcode(rs.getString("o.billing_postcode"));
				if (Settings.getInstance().isIncludeCountryCode4Customers()) {
					customerObject.setCountryCode(CountryCodes
							.getCountCode(bcountry));
				}
				customerObject
						.setEmail(rs.getString("customers_email_address"));

				customerObject.setDeliveryCompany(rs
						.getString("o.delivery_company"));
				customerObject.setDeliveryName(rs.getString("o.delivery_name"));
				customerObject.setDeliveryAddress(rs
						.getString("o.delivery_street_address"));
				customerObject.setDeliveryAddress2(rs
						.getString("o.delivery_suburb"));
				customerObject.setDeliveryCity(rs.getString("o.delivery_city"));
				String dcountry = rs.getString("o.delivery_country");
				customerObject.setDeliveryCountry(dcountry);
				customerObject.setDeliveryCodeOfCountry(CountryCodes
						.getCountCode(dcountry));// rs.getString("cu.code")
				customerObject.setDeliveryZipcode(rs
						.getString("o.delivery_postcode"));

				customerObject.setReference(rs.getString("customers_name"));

//				String personNumber = rs.getString("customers_personnummer");
				
				String personNumber = null;
				String companyTaxId = null;
				if(groupTableExists) {
					personNumber = rs.getString("customers_personnummer");
					companyTaxId = rs.getString("entry_company_tax_id");
				}

				if (personNumber != null && personNumber.length() > 0) {
					personNumber = personNumber.substring(2);
				}

				customerObject.setOrganizationNumber(personNumber);

//				String companyTaxId = rs.getString("entry_company_tax_id");
//				String companyTaxId = rs.getString("a.entry_company_tax_id");

				customerObject.setGroupName(rs.getString("customers_group_name"));
				
				int customerGroupShowTaxId = rs.getInt("customers_group_show_tax");
				int customerGroupId = rs.getInt("customers_group_id");
				logger.info("customerGroupShowTaxId  $$ "+customerGroupShowTaxId);

				// overwrites customers person number
				if (companyTaxId != null && companyTaxId.length() > 0) {
					customerObject.setOrganizationNumber(companyTaxId);
				}

				// billing
				// customerObject.set

				try {
					exportResult = inserCustomer(customerObject,updateCustomer);
					exportResult.setCustomerGroupShowTaxId(customerGroupShowTaxId);
					exportResult.setCustomerGroupId(customerGroupId);
				} catch (Exception e) {
					exportResult.setMessage(ExportResult.OSC_CUSTOMER_EXPORT_FAILURE_CODE,e.getMessage());
					// exportResult.set = String.valueOf(snumber);
					e.printStackTrace();
				}

			} else {
				exportResult.setMessage(ExportResult.OSC_CUSTOMER_INVALID_CODE,MessageBundle.getMessage("invalid.customer.number"));
			}
			
			printValues(rs);

			/*java.sql.ResultSetMetaData rsmd = rs.getMetaData();
			  for (int i = 1; i <= rsmd.getColumnCount(); i++) { try {
			  logger.info(rsmd.getColumnName(i)+"\t:"+rs.getObject(i)); }
			  catch (Exception e) { 
				 //TODO: handle exception
			  } 
				  
			}*/
			 

		} catch (Exception e) {
			exportResult.setMessage(ExportResult.OSC_CUSTOMER_EXPORT_FAILURE_CODE,e.getMessage());

			logger.error("Customer export failed ",e);
		} finally {

			try {
				rs.close();
				stmt.close();
				c.close();

			} catch (Exception e2) {
				logger.error("Error closing connection ",e2);
			}
		}

		return exportResult;

	}

	/*
	 * public String getMessage() { // TODO Auto-generated method stub return
	 * message; }
	 */

	public void printValues(ResultSet rs) {

		try {
			java.sql.ResultSetMetaData rsmd = rs.getMetaData();
			int c = rsmd.getColumnCount();
			for (int i = 01; i <= c; i++) {
				try {
					logger.debug(rsmd.getColumnName(i) + ":"
							+ rs.getObject(i));

				} catch (Exception e) {
					// TODO: handle exception
				}

			}

		} catch (Exception e) {
			logger.error("Error while printing values", e);
		}

	}

	// inserting customer submit
	public ExportResult insertCustomer(int parseInt, boolean updateCustomer) {
		
		boolean groupTableExists = OSCommerceAction.isTableExists("customers_groups");

		logger.info("inside getCustomerId group exists "+groupTableExists);

		String sql = "select c.*,a.*,con.*,cg.* from customers c,address_book a,countries con,customers_groups cg where "
				+ "c.customers_id = a.customers_id and "
				+ "c.customers_group_id = cg.customers_group_id and "
				+ "con.countries_id = a.entry_country_id and "
				+ "c.customers_id =" + parseInt;
		
		if(!groupTableExists) {
			sql = "select c.*,a.*,con.*,0 customers_group_id,'' customers_group_name,-1 customers_group_show_tax from customers c,address_book a,countries con where "
				+ "c.customers_id = a.customers_id and "
//				+ "c.customers_group_id = cg.customers_group_id and "
				+ "con.countries_id = a.entry_country_id and "
				+ "c.customers_id =" + parseInt;
		}

		logger.info("customer export sql " + sql);
		
		CustomerObject customerObject = new CustomerObject();

		ExportResult exportResult = new ExportResult();

		java.sql.Connection c = null;
		Statement stmt = null;
		ResultSet rs = null;

		try {
			String url = Settings.getInstance().getConnectionURL();
			String user = Settings.getInstance().getUserName();
			String password = Settings.getInstance().getPassword();
			String driver = Settings.getInstance().getDriverClassName();

			Class.forName(driver);
			// DriverManager.getConnection(url, user, password);
			// Session session = sessionFactory.openSession();
			// java.sql.Connection c =
			// sessionFactory.openSession().connection();
			c = DriverManager.getConnection(url, user, password);

			stmt = c.createStatement();
			rs = stmt.executeQuery(sql);


			if (rs.next()) {
				// printValues(rs);

				int snumber = rs.getInt("c.customers_id");
				// customerObject.setCompayName(rs.getString("customers_company"));
				String customerName = rs.getString("customers_firstname");
				String lastName = rs.getString("customers_lastname");
				customerObject.setCustomerName(customerName + " " + lastName);
				customerObject.setCustomerNumber(snumber);
				customerObject.setCompayName(rs.getString("entry_company"));
//				cus
				// customerObject.setCustomerNumber(rs.getInt("customers_id"));
				customerObject.setMailAdrress1(rs
						.getString("entry_street_address"));
				customerObject.setMailAddress2(rs.getString("entry_suburb"));
				customerObject.setCity(rs.getString("entry_city"));
				String bcountry = rs.getString("countries_name");
				customerObject.setCountry(bcountry);
				customerObject.setTelephone(rs
						.getString("c.customers_telephone"));
				
//				customerObject.setCustomerFax("customers_fax");

				/*
				 * customerObject.setTelephone2(rs
				 * .getString("c.customers_telephone"));
				 */
				
				customerObject.setGroupName(rs.getString("customers_group_name"));
				
				customerObject.setGroupName(rs.getString("customers_group_name"));
				
				int customerGroupShowTaxId = rs.getInt("customers_group_show_tax");
				
				int customerGroupId = rs.getInt("customers_group_id");
				customerObject.setGroupId(customerGroupId);

				customerObject.setCustomerFax(rs.getString("c.customers_fax"));
				
//				logger.info("fax "+customerObject.getCustomerFax());

				customerObject.setZipcode(rs.getString("entry_postcode"));
				if (Settings.getInstance().isIncludeCountryCode4Customers()) {
					customerObject.setCountryCode(CountryCodes
							.getCountCode(bcountry));
				}
				customerObject
						.setEmail(rs.getString("customers_email_address"));

				// customerObject.setDeliveryCompany(rs.getString("entry_company"));
				// customerObject.setDeliveryName(rs.getString("customers_firstname"));
				// customerObject.setDeliveryAddress(rs
				// .getString("entry_street_address"));
				// customerObject.setDeliveryAddress2(rs
				// .getString("entry_suburb"));
				// customerObject.setDeliveryCity(rs.getString("entry_city"));
				// String dcountry = rs.getString("countries_name");
				// customerObject.setDeliveryCountry(dcountry);
				// customerObject.setDeliveryCodeOfCountry(CountryCodes
				// .getCountCode(dcountry));// rs.getString("cu.code")
				// customerObject.setDeliveryZipcode(rs
				// .getString("entry_postcode"));

				// customerObject.setReference(rs.getString("billing_name"));

				String personNumber = null;
				String tax_id = null;
				if(groupTableExists) {
					personNumber = rs.getString("customers_personnummer");
					tax_id = rs.getString("entry_company_tax_id");
				}

				if (personNumber != null && personNumber.length() > 0) {
					personNumber = personNumber.substring(2);
				}
				

				// personNumber = "730521-3675";

				logger.info("Person number " + personNumber);
				if(tax_id != null && tax_id.length() > 0) {
					customerObject.setOrganizationNumber(tax_id);
				}else {
					customerObject.setOrganizationNumber(personNumber);
				}
				// billing
				// customerObject.set
				
				printValues(rs);

				try {
					exportResult = inserCustomer(customerObject,updateCustomer);
					
					exportResult.setCustomerGroupShowTaxId(customerGroupShowTaxId);
					exportResult.setCustomerGroupId(customerGroupId);

				} catch (Exception e) {
					// exportResult = String.valueOf(snumber);
					logger.error("Error while exporting customer", e);
				}

			} else {
				exportResult.setMessage(ExportResult.OSC_CUSTOMER_INVALID_CODE,MessageBundle.getMessage("invalid.customer.number"));
			}

			/*
			 * for (int i = 1; i <= rsmd.getColumnCount(); i++) { try {
			 * logger.info(rsmd.getColumnName(i)+"\t"+rs.getObject(i)); }
			 * catch (Exception e) { // TODO: handle exception } }
			 */

		} catch (Exception e) {
			e.printStackTrace();
		} finally {

			try {
				rs.close();
				stmt.close();
				c.close();

			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}

		return exportResult;

	}

	public static void main(String[] args) {

		String system = Settings.getInstance().getSystemPath();
		String company = Settings.getInstance().getCompanyPath();
		String s = Settings.getInstance().getLibraryPath();
		System.out.println("company path "+company);

		ExportResult message = new ExportResult();

		JInterLink j = JInterLink.getInstance();
		try {

			j.open(s, system, company);
			// Article article = JInterLinkRegisterFactory.createArticle();

			// String orderId = "7140";
			// String customerInsert = "true";

			if (true) {
				CustomersAction orderExport = new CustomersAction();
				int cno = 1;
				cno = 75;
				cno = 7607;
				message = orderExport.insertCustomer(cno, false);
			} else {
				message.setMessage(ExportResult.OSC_ORDER_EXPORT_FAILURE_CODE,"Please provide valid OrderId");
			}

			j.close();

		} catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		}

		System.out.println("message " + message.getResultMessage());

	}

}
